<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%

	String username = request.getParameter("username");
	String password = request.getParameter("password");
	String remember = request.getParameter("remember");
	Cookie[] cs = request.getCookies();
	for(Cookie c : cs){
		if("username".equals(c.getName())){
			username = c.getValue();
		}
		
	}
	
	
	System.out.print(remember);
	
	if("admin".equals(username) && "admin".equals(password))
	{
		session.setAttribute("loginUserName", "管理员");
		Integer _count = (Integer)application.getAttribute("count");
		if(_count==null){
			application.setAttribute("count", 1);
		}else{
			application.setAttribute("count", _count+1);
		}
		
		if("on".equals(remember)){
			Cookie cookieUsername = new Cookie("username",username);
			cookieUsername.setMaxAge(60*2);
			
			cookieUsername.getName();
			
			Cookie cookiePassword = new Cookie("password",password);
			cookiePassword.setMaxAge(60*2);
			
			response.addCookie(cookiePassword);
			response.addCookie(cookieUsername);
		}
		
		
		response.sendRedirect("index.jsp");
	}else{
	
		request.setAttribute("msg", "用户名或密码错误！");
		request.getRequestDispatcher("login.jsp").forward(request, response);
	}
	
	

%>
